package org.jetnuke.modules.your_account;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.jforum.dao.DataAccessDriver;
import net.jforum.dao.UserDAO;
import net.jforum.entities.User;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.util.JetUtil;

public class DoChangeTheme implements IAction {
	int theme;

	/**
	 * @param theme
	 *            The theme to set.
	 */
	public void setTheme(int theme) {
		this.theme = theme;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.jetnuke.common.IAction#exec(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse,
	 *      org.apache.velocity.VelocityContext, org.jetnuke.common.IModuleInfo,
	 *      java.lang.String)
	 */
	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {

		UserDAO um=DataAccessDriver.getInstance().newUserDAO();
		User us=um.selectById(ui.getID());
		us.setThemeId(theme);
		um.update(us);
		//users user = usersPeer.retrieveByPK(ui.getID());
		//user.setTHEME(theme);
		//user.save();
		JetUtil.redirect(vc,response,request.getContextPath()+"/do/your_account/home");
		return null;
	}

}
